<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head><title>Struts 2 Training Materials</title>
</head>

<body>
<c:set var="root" value="${pageContext.request.contextPath}"/>
<div align="center">
    <center>
        <table border="1" cellspacing="1" width="400">
            <tr>
                <td width="390"><font size="4"><b>Struts 2 Value Stack & OGNL Expressions </b></font></td>
            </tr>
            <tr>
                <td width="384">
                    <ul>
                        <li>
                            <a href="#"> What is Value Stack ?? </a>
                            <br>
                            <br>
                            <img src="../../images/valuestack2.jpg" border="0" width="500" height="360">
                            <br>
                            <br>
                            - A value stack object is created per request basis.
                            <br>
                            - Objects like Actions , Model and any java resources are created and placed.
                            <br>
                            <br>
                            <img src="../../images/valuestack1.JPG" border="0" width="400" height="300">
                            <br>
                            <br>
                            - These objects are Thread Local and end it's life when the request cycle is completed.
                            <br>
                            - One of the major advantages of Valuestack is that any object with which we work or the
                            model objects are available to the response UI pages through the OGNL expression language.
                            We do not need to set every object to an attribute map to access them in response
                            <br>
                            <br>
                            <img src="../../images/stackimage.jpg" border="0">
                            <br>
                            <br>
                            - Value stack has 2 parts which are Object Stack and Context Map.
                            <br>
                            - <b>Object Stack : </b> is a Stack which stores the references to the Objects that are
                            created to handle the request. The name itself speaks that it is a stack.
                            The objects created are referenced in a stack and can be accessed using Indexes.
                            <br>
                            - <b>Context Map : </b> is a place where the Maps like Request Parameters, Request
                            Attributes, Session Attributes and Application Attributes.
                            The context map also has an extra map called attribute map.The attribute map helps to search
                            through all the attributes starting from Request scope, session scope and then in the
                            application scope.
                            Where ever it finds the requested attribute first, it returns the value from that scope.
                        </li>
                        <li>
                            <a href="#"> What are OGNL Expressions ?? </a>
                            <br>
                            - OGNL stands for Object Graph Navigation Language.
                            <br>
                            - OGNL offers the expression language which can be part of form tags and UI pages. This
                            expression language helps to map the entered values to the destination properties of the
                            Java Bean to which they have to be set.
                            <br>
                            - OGNL looks for the properties in the Objects that are loaded in the Valuestack and when
                            found, the values are converted and set to Model objects.
                            <br>
                            <br>
                            <img src="../../images/ognl.jpg" border="0">
                            <br>
                            <br>
                            - The framework sets the OGNL context to be our ActionContext, and the value stack to be the
                            OGNL root object.
                            <br>
                            - Context map has application , session, value stack (root), request , parameters, attr
                            (searches page, request, session, then application scopes)
                            <br>
                            - The Action instance is always pushed onto the value stack. Because the Action is on the
                            stack, and the stack is the OGNL root, references to Action properties can omit the #
                            marker. But, to access other objects in the ActionContext, we must use the # notation so
                            OGNL knows not to look in the root object, but for some other object in the ActionContext.
                            <br>
                        </li>
                        <li>
                            <a href="#"> Accessing the context map using expression language ?? </a>
                            <br>
                            - Objects in the ActionContext are referred using the pound symbol, however, the objects in
                            the value stack can be directly referenced, for example if employee is a property of an
                            action class then it can ge referenced as follows: <s:property value="name"/>
                            <br>
                            - Request Parameters are returned in the form of Array. So to retrieve a parameter, we need
                            to know in which index a parameter is present. <s:property value="#parameters.count[0]"/>
                            will fetch the first request parameter.
                            <br>
                            - Request attributes: Given below are the expressions that can be used to access the request
                            attributes.
                            #request.user.name
                            #request['user']['name
                            <br>
                            - Session attributes : #session.user.name
                            <br>
                            - Application attributes - #application.user.name
                            <br>
                            - Attribute map - #attr['user']['name']
                            <br>
                            - Use of % (percent sign)
                            %{ OGNL expression } is used to force OGNL evaluation of an attribute that would normally be
                            interpreted as a String literal.
                            Example: <s:property value="myProperty" default="%{myDynamicDefaultValue}"/>
                        </li>
                    </ul>
                </td>
            </tr>
            <tr>
                <td>
                    <a href="${root}/index.jsp">HOME</a>
                </td>
            </tr>
        </table>
    </center>
</div>
</body>
</html>